// 时间搓转换为时间格式
export function getFormTime(timestamp: number = 0, formats: any = null) {
  // 1. Y-m-d
  // 2. Y-m-d H:i:s
  formats = formats || 'Y-m-d H:i:s'
  const zero = function (value) {
    if (value < 10) {
      return '0' + value
    }
    return value
  }
  const myDate = timestamp ? new Date(timestamp) : new Date()
  const year = myDate.getFullYear()
  const month = zero(myDate.getMonth() + 1)
  const day = zero(myDate.getDate())
  const hour = zero(myDate.getHours())
  const minite = zero(myDate.getMinutes())
  const second = zero(myDate.getSeconds())
  return formats.replace(/Y|m|d|H|i|s/gi, function (matches) {
    return {
      Y: year,
      m: month,
      d: day,
      H: hour,
      i: minite,
      s: second
    }[matches]
  })
}

// 获取当前日期
export function getNowFormatDate() {
  const date = new Date()
  const seperator1 = '-'
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const strDate = date.getDate()
  let monthS = ''
  let strDateS = ''
  if (month >= 1 && month <= 9) {
    monthS = '0' + month
  }
  if (strDate >= 0 && strDate <= 9) {
    strDateS = '0' + strDate
  }
  const currentdate = year + seperator1 + monthS + seperator1 + strDateS
  return currentdate
}

// 获取今天
export function getToDay() {
  const date = new Date()
  const seperator1 = '-'
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const strDate = date.getDate()
  let monthS = ''
  let strDateS = ''
  if (month >= 1 && month <= 9) {
    monthS = '0' + month
  }
  if (strDate >= 0 && strDate <= 9) {
    strDateS = '0' + strDate
  }
  const currentdate = year + seperator1 + monthS + seperator1 + strDateS
  return [currentdate + ' 00:00:00', currentdate + ' 23:59:59']
}
